using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Designer
{
    public class SimpleRectangleTransform :TransformBase
    {
        private bool bolEnable;
        private bool bolVisible;
        private int intFlag2;
        private int intFlag3;
        private int intPageIndex;
        protected RectangleF myDescRect;
        protected RectangleF mySourceRect;
        private object objTag;

        public SimpleRectangleTransform()
        {
            this.bolEnable = true;
            this.bolVisible = true;
            this.objTag = null;
            this.intPageIndex = 0;
            this.intFlag2 = 0;
            this.intFlag3 = 0;
            this.mySourceRect = RectangleF.Empty;
            this.myDescRect = RectangleF.Empty;
        }

        public SimpleRectangleTransform(RectangleF vSourceRect, RectangleF vDescRect)
        {
            this.bolEnable = true;
            this.bolVisible = true;
            this.objTag = null;
            this.intPageIndex = 0;
            this.intFlag2 = 0;
            this.intFlag3 = 0;
            this.mySourceRect = RectangleF.Empty;
            this.myDescRect = RectangleF.Empty;
            this.mySourceRect = vSourceRect;
            this.myDescRect = vDescRect;
        }

        public override bool ContainsSourcePoint(int x, int y)
        {
            return this.mySourceRect.Contains((float)x, (float)y);
        }

        public override Point TransformPoint(int x, int y)
        {
            PointF p = this.TransformPointF((float)x, (float)y);
            return new Point((int)p.X, (int)p.Y);
        }

        public override PointF TransformPointF(float x, float y)
        {
            x -= this.mySourceRect.Left;
            y -= this.mySourceRect.Top;
            if ((this.mySourceRect.Width != this.myDescRect.Width) && (this.mySourceRect.Width != 0f))
            {
                x = (x * this.myDescRect.Width) / this.mySourceRect.Width;
            }
            if ((this.mySourceRect.Height != this.myDescRect.Height) && (this.mySourceRect.Height != 0f))
            {
                y = (y * this.myDescRect.Height) / this.mySourceRect.Height;
            }
            return new PointF(x + this.DescRect.Left, y + this.DescRect.Top);
        }

        public override Size TransformSize(int w, int h)
        {
            if ((this.mySourceRect.Width != this.myDescRect.Width) && (this.mySourceRect.Width != 0f))
            {
                w = (int)((w * this.myDescRect.Width) / this.mySourceRect.Width);
            }
            if ((this.mySourceRect.Height != this.myDescRect.Height) && (this.mySourceRect.Height != 0f))
            {
                h = (int)((h * this.myDescRect.Height) / this.mySourceRect.Height);
            }
            return new Size(w, h);
        }

        public override SizeF TransformSizeF(float w, float h)
        {
            if ((this.mySourceRect.Width != this.myDescRect.Width) && (this.mySourceRect.Width != 0f))
            {
                w = (w * this.myDescRect.Width) / this.mySourceRect.Width;
            }
            if ((this.mySourceRect.Height != this.myDescRect.Height) && (this.mySourceRect.Height != 0f))
            {
                h = (h * this.myDescRect.Height) / this.mySourceRect.Height;
            }
            return new SizeF(w, h);
        }

        public override Point UnTransformPoint(Point p)
        {
            PointF p1 = this.UnTransformPointF((float)p.X, (float)p.Y);
            return new Point((int)p1.X, (int)p1.Y);
        }

        public override Point UnTransformPoint(int x, int y)
        {
            PointF p1 = this.UnTransformPointF((float)x, (float)y);
            return new Point((int)p1.X, (int)p1.Y);
        }

        public override PointF UnTransformPointF(float x, float y)
        {
            x -= this.DescRect.Left;
            y -= this.DescRect.Top;
            if ((this.mySourceRect.Width != this.myDescRect.Width) && (this.myDescRect.Width != 0f))
            {
                x = (x * this.mySourceRect.Width) / this.myDescRect.Width;
            }
            if ((this.mySourceRect.Height != this.myDescRect.Height) && (this.myDescRect.Height != 0f))
            {
                y = (y * this.mySourceRect.Height) / this.myDescRect.Height;
            }
            return new PointF(x + this.SourceRect.Left, y + this.SourceRect.Top);
        }

        public override Size UnTransformSize(int w, int h)
        {
            if ((this.mySourceRect.Width != this.myDescRect.Width) && (this.myDescRect.Width != 0f))
            {
                w = (int)((w * this.mySourceRect.Width) / this.myDescRect.Width);
            }
            if ((this.mySourceRect.Height != this.myDescRect.Height) && (this.myDescRect.Height != 0f))
            {
                h = (int)((h * this.mySourceRect.Height) / this.myDescRect.Height);
            }
            return new Size(w, h);
        }

        public override SizeF UnTransformSizeF(float w, float h)
        {
            if ((this.mySourceRect.Width != this.myDescRect.Width) && (this.myDescRect.Width != 0f))
            {
                w = (w * this.mySourceRect.Width) / this.myDescRect.Width;
            }
            if ((this.mySourceRect.Height != this.myDescRect.Height) && (this.myDescRect.Height != 0f))
            {
                h = (h * this.mySourceRect.Height) / this.myDescRect.Height;
            }
            return new SizeF(w, h);
        }

        public Rectangle DescRect
        {
            get
            {
                return new Rectangle((int)this.myDescRect.Left, (int)this.myDescRect.Top, (int)this.myDescRect.Width, (int)this.myDescRect.Height);
            }
            set
            {
                this.myDescRect = new RectangleF((float)value.Left, (float)value.Top, (float)value.Width, (float)value.Height);
            }
        }

        public RectangleF DescRectF
        {
            get
            {
                return this.myDescRect;
            }
            set
            {
                this.myDescRect = value;
            }
        }

        public bool Enable
        {
            get
            {
                return this.bolEnable;
            }
            set
            {
                this.bolEnable = value;
            }
        }

        public int Flag2
        {
            get
            {
                return this.intFlag2;
            }
            set
            {
                this.intFlag2 = value;
            }
        }

        public int Flag3
        {
            get
            {
                return this.intFlag3;
            }
            set
            {
                this.intFlag3 = value;
            }
        }

        public Point OffsetPosition
        {
            get
            {
                return new Point((int)(this.myDescRect.Left - this.mySourceRect.Left), (int)(this.myDescRect.Top - this.mySourceRect.Top));
            }
        }

        public PointF OffsetPositionF
        {
            get
            {
                return new PointF(this.myDescRect.Left - this.mySourceRect.Left, this.myDescRect.Top - this.mySourceRect.Top);
            }
        }

        public int PageIndex
        {
            get
            {
                return this.intPageIndex;
            }
            set
            {
                this.intPageIndex = value;
            }
        }

        public Rectangle SourceRect
        {
            get
            {
                return new Rectangle((int)this.mySourceRect.Left, (int)this.mySourceRect.Top, (int)this.mySourceRect.Width, (int)this.mySourceRect.Height);
            }
            set
            {
                this.mySourceRect = new RectangleF((float)value.Left, (float)value.Top, (float)value.Width, (float)value.Height);
            }
        }

        public RectangleF SourceRectF
        {
            get
            {
                return this.mySourceRect;
            }
            set
            {
                this.mySourceRect = value;
            }
        }

        public object Tag
        {
            get
            {
                return this.objTag;
            }
            set
            {
                this.objTag = value;
            }
        }

        public bool Visible
        {
            get
            {
                return this.bolVisible;
            }
            set
            {
                this.bolVisible = value;
            }
        }

        public float XZoomRate
        {
            get
            {
                return (this.myDescRect.Width / this.mySourceRect.Width);
            }
        }

        public float YZoomRate
        {
            get
            {
                return (this.myDescRect.Height / this.mySourceRect.Height);
            }
        }
    }
}
